//
// Created by yasin on 2024/9/9.
//

#ifndef WEBRTC_CLIENT__HTTP_UTILS_H_
#define WEBRTC_CLIENT__HTTP_UTILS_H_


#include "rtc_base/thread.h"
#include <string>
#include <functional>

namespace ohosrtc::http_utils {

using HttpSuccessCallback = std::function<void(const std::string&)>;
using HttpFailCallback = std::function<void(const std::string &)>;

void HttpGet(const std::string &url, HttpSuccessCallback success_cb = nullptr, HttpFailCallback fail_cb = nullptr);
void HttpPost(const std::string &host, const std::string &path, HttpSuccessCallback success_cb = nullptr, HttpFailCallback fail_cb = nullptr);
void HttpDelete(const std::string &host, const std::string &path, HttpSuccessCallback success_cb = nullptr, HttpFailCallback fail_cb = nullptr);

inline void HttpGet(std::shared_ptr<rtc::Thread> thread, const std::string &url, HttpSuccessCallback success_cb = nullptr, HttpFailCallback fail_cb = nullptr) {
  thread->PostTask([=]() {
    HttpGet(url, success_cb, fail_cb);
  });
}

inline void HttpPost(std::shared_ptr<rtc::Thread> thread, const std::string &host, const std::string &path, HttpSuccessCallback success_cb = nullptr, HttpFailCallback fail_cb = nullptr) {
  thread->PostTask([=]() {
    HttpPost(host, path, success_cb, fail_cb);
  });
}

inline void HttpDelete(std::shared_ptr<rtc::Thread> thread, const std::string &host, const std::string &path, HttpSuccessCallback success_cb = nullptr, HttpFailCallback fail_cb = nullptr) {
  thread->PostTask([=]() {
    HttpDelete(host, path, success_cb, fail_cb);
  });
}

}


#endif //WEBRTC_CLIENT__HTTP_UTILS_H_
